// Copyright (c) 2023 Presto Labs Pte. Ltd.
// Author: fengyang

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#include <simdjson.h>

#include "coin2/base/log.h"
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::mercado::feed_v4 {
namespace impl {
using namespace std::string_literals;
using coin2::exchange::base::market::ExchangeType;
using coin2::exchange::base::market::MarketType;

class MercadoFeedProcessor : public coin2::exchange::base::feed::FeedParsingProcessor {

  static constexpr auto MAX_PACKET_PAYLOAD_SIZE = 4 * 1024 * 1024; // 4MB buffer
 public:
  MercadoFeedProcessor(
      const std::string& system_name,
      const MarketExchangeApi& mea,
      const coin2::exchange::di::ConstantInjection& ci,
      const coin2::exchange::feed::RawParserConfig& config)
      : FeedParsingProcessor(system_name, mea, ci, config, "") {
      if (auto err = parser_.allocate(MAX_PACKET_PAYLOAD_SIZE); err)
      {
        LOG(ERROR) << simdjson::error_message(err);
      }
  }

  void OnTopicRecord(const coin2::exchange::base::executor::TopicRecordPacket& packet) override;

 protected:
  simdjson::ondemand::parser parser_;
};
}  // namespace impl
using impl::MercadoFeedProcessor;
}  // namespace coin2::exchange::mercado::feed_v4
